package xiaohu.day5.HJ50;

import java.util.*;



public class Main3 {
    public static HashMap<Character, Integer> map = new HashMap<Character, Integer>() {
        {
            put('+', 1);
            put('-', 1);
            put('*', 2);
            put('/', 2);

        }
    };

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String str = scanner.nextLine();
            //处理括号
            str=str.replaceAll("\\{","(").replaceAll("\\}", ")")
                    .replaceAll("\\[", "(").replaceAll("\\]", ")");
            //处理负数
            for (int i = 0; i < str.length(); i++) {
                char at = str.charAt(i);
                if (at == '-' ) {
                    if (i == 0 || (!Character.isDigit(str.charAt(i - 1)) && str.charAt(i-1)!=')')) {
                        str = str.substring(0, i) + "0" + str.substring(i);
                    }
                }
            }

            //中缀转后缀
            Stack<Character> chStack = new Stack<>();
            ArrayList<String> strZ = new ArrayList<>();
            for (int i = 0; i < str.length(); i++) {
                char at = str.charAt(i);
                if (!Character.isDigit(at)) {//不是数字
                    if (at == '(') {
                        chStack.push(at);
                    } else if (at == ')') {
                        while (!chStack.isEmpty() && chStack.peek() != '(') {
                            Character pop = chStack.pop();
                            strZ.add(String.valueOf(pop));
                        }
                        chStack.pop();//弹出左括号
                    } else {
                        while (!chStack.isEmpty() &&chStack.peek() != '(' && map.get(chStack.peek()) >= map.get(at)) {
                            Character pop = chStack.pop();
                            strZ.add(String.valueOf(pop));
                        }
                        chStack.push(at);
                    }
                } else {//是数字
                    int tempNum = 0;
                    while (i<str.length() &&Character.isDigit(at)) {
                        tempNum = tempNum * 10 + at - '0';
                        i++;
                        if (i >= str.length()) {
                            break;
                        }
                        at = str.charAt(i);
                    }
                    i--;//要回退
                    strZ.add(String.valueOf(tempNum));
                }
            }
            //栈中剩余的运算符
            while (!chStack.isEmpty()) {
                Character pop = chStack.pop();
                strZ.add(String.valueOf(pop));
            }

            //后缀计算
            Stack<Integer> integerStack = new Stack<>();
            for (int i = 0; i < strZ.size(); i++) {
                String at = strZ.get(i);
                boolean flag=isNumber(at);
                if (flag) {
                    integerStack.push(Integer.valueOf(at));
                } else {
                    int num2 = integerStack.pop();
                    int num1 = integerStack.pop();
                    switch (at) {
                        case "+":
                            integerStack.push(num1 + num2);
                            break;
                        case "-":
                            integerStack.push(num1 - num2);
                            break;
                        case "*":
                            integerStack.push(num1 * num2);
                            break;
                        case "/":
                            integerStack.push(num1 / num2);
                            break;
                        default:
                            throw new RuntimeException("运算符错误");
                    }
                }
            }
            System.out.println(integerStack.pop());
        }
    }

    private static boolean isNumber(String at) {
        try {
            Integer.parseInt(at);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
